<?php
  class ListFactory extends kleotemplate{

    public $heading = null;
    public $values = null;
    public $sizes = null;
    public $query = null;
    public $buff = null;
    public $actions = 'blog';
    public $list_heading = null;
    public $list_content = null;
    public $bulk_actions = true;

    public function SetValues($heading, $values, $sizes, $query){
      $this->heading = $heading;
      $this->values = $values;
      $this->sizes = $sizes;
      $this->list_query = $this->query($query);
    }

    public function CompileList($checkbox=false){
      if($this->num_rows($this->list_query) !== 0){
	$this->list_showing = true;
      }

      $a=0;
      $i=1;
      foreach($this->heading as $head){
	$this->list_heading[$a]['i'] = $i;
	$this->list_heading[$a]['caption'] = $head;
	$this->list_heading[$a]['size'] = $this->sizes[$a];
	$a++;
	$i++;
      }
      $list_columns = $i;

      $i=0;
      while($row = $this->fetch_array($this->list_query)){
	$a=0;
	foreach($this->list_heading as $head){
	    switch($this->values[$a]){
	      case 'title':
		if($checkbox == true){
			$value = '<input onclick="AddCheckbox(\'entry_'.$row['id'].'\');" id="entry_'.$row['id'].'" type="checkbox" name="entry_'.$row['id'].'" />'.$row['title'];
		}
	      break;
	      case 'resume':
	      $value = strip_tags(substr($row['content'],0,128)).'...';
	      break;
	      case 'actions':
	      $value = ListFactory::ListActions($row,$a);
	      break;
	      default:
	      $value = $row[$this->values[$a]];
	      break;
	    } 
	  $this->list_content[$i]['value'] .= '<div class="'.$head['size'].'">'.$value.'</div>';
	  $a++;
	}
	$i++;
      }
      $data['content'] = $this->list_content;
      $data['heading'] = $this->list_heading;
      return $data;
    }
    function ListActions($row,$i){
	switch($this->actions){
	  case 'blog':
	    $actions = '<a href="?'.$_SERVER['QUERY_STRING'].'&delid='.$row['id'].'" onclick="return confirm(\''.L_ASK_DELETE_ENTRY.'\');">'.L_DELETE.'</a> | <a href="?module=admin&file=newpost.tpl&id='.$row['id'].'">'.L_EDIT.'</a>';
	  break;
	  case 'pages':
	    $actions = '<a href="?'.$_SERVER['QUERY_STRING'].'&delid='.$row['id'].'" onclick="return confirm(\''.L_ASK_DELETE_ENTRY.'\');">'.L_DELETE.'</a> | <a href="?module=admin&file=newpage.tpl&id='.$row['id'].'">'.L_EDIT.'</a>';
	  break;
	  case 'feelings':
	    $actions = '<a href="?'.$_SERVER['QUERY_STRING'].'&delid='.$row['id'].'" onclick="return confirm(\''.L_ASK_DELETE_ENTRY.'\');">'.L_DELETE.'</a> | <a href="?module=admin&file=newfeeling.tpl&id='.$row['id'].'">'.L_EDIT.'</a>';
	  break;
	  case 'comments':
		// Waiting moderation
		if($row['costatus'] == 0){
	  		$actions = '<a href="?module=admin&comment_action=approve&id='.$row['coid'].'">'.L_APPROVE.'</a> | <a href="?module=admin&comment_action=spam&id='.$row['coid'].'">'.L_SPAM.'</a>';
		// Approved
		} else if($row['costatus'] == 1){
	  		$actions = '<a href="?module=admin&comment_action=spam&id='.$row['coid'].'">'.L_SPAM.'</a> | <a href="?module=admin&comment_action=delete&id='.$row['coid'].'" onclick="return confirm(\''.L_ASK_DELETE_COMMENT.'\');">'.L_DELETE.'</a>';
		// Spam/Not approved
		} else if($row['costatus'] == 2){
	  		$actions = '<a href="?module=admin&comment_action=approve&id='.$row['coid'].'">'.L_NOT_SPAM.'</a> | <a href="?module=admin&comment_action=delete&id='.$row['coid'].'" onclick="return confirm(\''.L_ASK_DELETE_COMMENT.'\');">'.L_DELETE.'</a>';
		}
	  break;
	  default:
	    $actions = '<a href="?'.$_SERVER['QUERY_STRING'].'&delid='.$row['id'].'" onclick="return confirm(\''.L_ASK_DELETE_ENTRY.'\');">'.L_DELETE.'</a> | <a href="?module=admin&file=newpage.tpl&id='.$row['id'].'">'.L_EDIT.'</a>';
	  break;
	}
	return $actions;
    }
  }
?>
